package com.crscd.ai.controller;

import jakarta.annotation.Resource;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.model.ChatModel;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

/**
 * Created with IntelliJ IDEA.
 *
 * @description:
 * @author: liuziyang
 * @since: 9/30/25 8:56 AM
 * @modifiedBy:
 * @version: 1.0
 */
@RestController
public class StreamOutputController {
  @Resource(name = "deepseek")
  private ChatModel deepseekChatModel;

  @Resource(name = "qwen")
  private ChatModel qwenChatModel;

  @Resource(name = "deepseekChatClient")
  private ChatClient deepseekChatClient;

  @Resource(name = "qwenChatClient")
  private ChatClient qwenChatClient;

  @GetMapping(value = "/stream/chatflux1")
  public Flux<String> chatflux(
      @RequestParam(name = "question", defaultValue = "介绍下你自己") String question) {
    return deepseekChatModel.stream(question);
  }

  @GetMapping(value = "/stream/chatflux2")
  public Flux<String> chatflux2(
      @RequestParam(name = "question", defaultValue = "介绍下你自己") String question) {
    return qwenChatModel.stream(question);
  }

  @GetMapping(value = "/stream/chatflux3")
  public Flux<String> chatflux3(
      @RequestParam(name = "question", defaultValue = "介绍下你自己") String question) {
    return deepseekChatClient.prompt(question).stream().content();
  }

  @GetMapping(value = "/stream/chatflux4")
  public Flux<String> chatflux4(
      @RequestParam(name = "question", defaultValue = "介绍下你自己") String question) {
    return qwenChatClient.prompt(question).stream().content();
  }
}
